package com.dqhl.community.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.adapter.OrderPagerAdapter;
import com.dqhl.community.base.BaseActivity;

/**
 * Created by cheng on 2016/8/30.
 * 我的订单界面
 */
public class OrderActivity extends BaseActivity implements View.OnClickListener {

    private ImageView ivTopBack;
    private TextView tvTopTitle;
    private TextView mTvUnFinish;
    private TextView mTvFinish;
    private View lineUnfinish;
    private View lineFinish;
    private ViewPager mVpOrder;
    private ImageView mImOperation;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);

        initView();

    }

    /**
     * 初始化控件
     */
    private void initView() {
        mVpOrder = (ViewPager) findViewById(R.id.vp_order);

        ivTopBack = (ImageView) findViewById(R.id.iv_top_back);
        mImOperation = (ImageView) findViewById(R.id.tv_top_operation);
        ivTopBack.setVisibility(View.VISIBLE);
        mImOperation.setVisibility(View.INVISIBLE);
        tvTopTitle = (TextView) findViewById(R.id.tv_top_title);
        mTvUnFinish = (TextView) findViewById(R.id.tv_unfinish);
        mTvFinish = (TextView) findViewById(R.id.tv_finish);
        lineUnfinish = findViewById(R.id.line_unfinish);
        lineFinish = findViewById(R.id.line_finish);
        tvTopTitle.setText(R.string.txt_order);

        ivTopBack.setOnClickListener(this);
        mTvUnFinish.setOnClickListener(this);
        mTvFinish.setOnClickListener(this);

        mVpOrder.setAdapter(new OrderPagerAdapter(getSupportFragmentManager()));
        mVpOrder.setCurrentItem(0, true);
        mVpOrder.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        mTvUnFinish.setTextColor(ContextCompat.getColor(OrderActivity.this, R.color.orange));
                        mTvFinish.setTextColor(ContextCompat.getColor(OrderActivity.this, R.color.black_light));
                        lineUnfinish.setBackgroundColor(ContextCompat.getColor(OrderActivity.this, R.color.orange));
                        lineFinish.setBackgroundColor(ContextCompat.getColor(OrderActivity.this, R.color.white));
                        break;
                    case 1:
                        mTvUnFinish.setTextColor(ContextCompat.getColor(OrderActivity.this, R.color.black_light));
                        mTvFinish.setTextColor(ContextCompat.getColor(OrderActivity.this, R.color.orange));
                        lineUnfinish.setBackgroundColor(ContextCompat.getColor(OrderActivity.this, R.color.white));
                        lineFinish.setBackgroundColor(ContextCompat.getColor(OrderActivity.this, R.color.orange));
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_top_back:
                finish();
                break;
            case R.id.tv_unfinish:
                mVpOrder.setCurrentItem(0, true);
                break;
            case R.id.tv_finish:
                mVpOrder.setCurrentItem(1, true);
                break;

        }
    }
}
